package a08_回溯算法;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * a11_子集复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/11
 */
public class a11_子集复习3 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        LinkedList<Integer> path = new LinkedList<>();
        traversal(result, path, nums, 0);
        return result;
    }

    private void traversal(List<List<Integer>> result,
                           LinkedList<Integer> path,
                           int[] nums,
                           int startIdx){
        result.add(new ArrayList<>(path));
        for (int i = startIdx; i < nums.length; i++) {
            path.add(nums[i]);
            traversal(result, path, nums, i + 1);
            path.removeLast();
        }
    }
}
